<template> 
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="推广员ID：">
            <el-input v-model="listQuery.channleMemberId" class="input-width" placeholder="请填写推广员ID"></el-input>
          </el-form-item>
          <el-form-item label="推广员名称：">
            <el-input v-model="listQuery.channleName" class="input-width" placeholder="请填写推广员名称"></el-input>
          </el-form-item>
          <el-form-item label="用户ID：">
            <el-input v-model="listQuery.memberId" class="input-width" placeholder="请填写用户ID"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称：">
            <el-input v-model="listQuery.memberName" class="input-width" placeholder="请填写用户昵称"></el-input>
          </el-form-item>
          <el-form-item label="结算科目：">
            <el-select v-model="listQuery.type" class="input-width" placeholder="全部" clearable>
              <el-option v-for="item in subjects"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="消费者城市：">-->
            <!--<el-select v-model="listQuery.city" class="input-width" placeholder="全部" clearable>-->
              <!--<el-option v-for="item in citys"-->
                         <!--:key="item.value"-->
                         <!--:label="item.label"-->
                         <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="交易时间：">
            <el-date-picker
              class="data-pick-style"
              v-model="listQuery.startDateTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择开始日期时间">
            </el-date-picker>
            -
            <el-date-picker
              class="data-pick-style"
              v-model="listQuery.endDateTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择结束日期时间">
            </el-date-picker>
          </el-form-item>
          <el-button
            class="search-Btn"
            type="primary"
            size="medium"
            icon="el-icon-search"
            @click="handleSearchList()">
            检索
          </el-button>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table ref="orderTable"
                :data="list"
                style="width: 100%;"
                v-loading="listLoading" border>
        <el-table-column label="流水号" width="80" align="center">
          <template slot-scope="scope">{{scope.row.id}}</template>
        </el-table-column>
        <el-table-column label="推广员ID"  align="center">
          <template slot-scope="scope">{{scope.row.channleMemberId}}</template>
        </el-table-column>
        <el-table-column label="推广员名称"align="center">
          <template slot-scope="scope">{{scope.row.channelName}}</template>
        </el-table-column>
        <el-table-column label="用户ID" align="center">
          <template slot-scope="scope">{{scope.row.memberId}}</template>
        </el-table-column>
        <el-table-column label="用户昵称" width="150" align="center">
          <template slot-scope="scope">{{scope.row.memberName}}</template>
        </el-table-column>
        <el-table-column label="结算科目" width="120" align="center">
          <template slot-scope="scope">{{scope.row.promoType | formatType}}</template>
        </el-table-column>
        <el-table-column label="交易金额" width="120"  align="center">
          <template slot-scope="scope">{{scope.row.money | formateMoney}}</template>
        </el-table-column>
        <el-table-column label="交易前金额" width="120"  align="center">
          <template slot-scope="scope">{{scope.row.beforeMoney | formateMoney}}</template>
        </el-table-column>
        <el-table-column label="交易后金额" width="120"   align="center">
          <template slot-scope="scope">{{scope.row.afterMoney | formateMoney}}</template>
        </el-table-column>
        <el-table-column label="交易时间" width="180" align="center">
          <template slot-scope="scope">{{scope.row.createTime}}</template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import {formatDate,moneyFormat} from '@/utils/tools';
  import { Message } from 'element-ui'
  import requestApi from '@/api/index.js'

  const defaultListQuery = {
    pageNum: 1,
    pageSize: 10,
    channleMemberId:'',
    channleName: '',
    memberId: '',
    memberName: '',
    type: '',
    startDateTime:'',
    endDateTime: ''
  };
  const typesArr = [
    {
      label: '办理激活ETC',
      value: 1
    }, {
      label: '高速券领取',
      value: 2
    }, {
      label: '高速券使用',
      value: 3
    }, {
      label: '停车券领取',
      value: 4
    },{
      label: '停车券使用',
      value: 5
    },{
      label: '代驾券领取',
      value: 6
    },{
      label: '代驾券使用',
      value: 7
    },{
      label: '洗车券领取',
      value: 8
    },{
      label: '洗车券使用',
      value: 9
    },
  ];
  export default {
    name: "orderList",
    data() {
      return {
        listQuery: Object.assign({}, defaultListQuery),
        listLoading: true,
        list: null,
        total: null,
        subjects: JSON.parse(JSON.stringify(typesArr))
      }
    },
    created() {
      this.getList();
    },
    filters: {
      formatCreateTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      },
      formatType(type) {
        let temp = '';
        for (let i = 0; i < typesArr.length; i++) {
          if (typesArr[i].value == type) {
            temp = typesArr[i].label;
            break;
          }
        }
        return temp;
      },
      formateMoney(val) {
        return moneyFormat(val);
      }
    },
    methods: {
      handleSearchList() {
        this.listQuery.pageNum = 1;
        this.getList();
      },
      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },
      getList() {
        this.listLoading = true;
        requestApi.getPromoItemList(this.listQuery).then((res) => {
          this.listLoading = false;
          if (res.code == 0) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            Message({
              message: res.message,
              type: 'error',
              duration: 3 * 1000
            })
          }
        }).catch(() => {
          Message({
            message:'服务器异常',
            type: 'error',
            duration: 3 * 1000
          })
        })
      },
    }
  }
</script>
<style scoped>
  .input-width {
    width: 203px;
  }
  .input-width-date {
    width: 340px;
  }
  .search-Btn {
    margin-left: 0px;
  }
</style>


